#include <signal.h>
#include <time.h>
#include <string.h>

#include "clock.h"
#include "signals.h"

void
vwm_init_clock(int milliseconds)
{
    timer_t             timer;
    long                nanoseconds;
    struct itimerspec   new_val;
    struct itimerspec   old_val;

    memset(&new_val,0,sizeof(new_val));
    memset(&old_val,0,sizeof(old_val));

    vwm_set_SIGALRM();

    timer_create(CLOCK_MONOTONIC,NULL,&timer);

    nanoseconds = milliseconds * 1000 * 1000;
    new_val.it_interval.tv_nsec = nanoseconds;
    new_val.it_value.tv_nsec = nanoseconds;

    timer_settime(timer,0,&new_val,&old_val);

    return;
}
